package com.treasure.mall.biz.service.core.live.impl;

import com.treasure.mall.biz.entity.live.LiveRoomUserRecordsPO;
import com.treasure.mall.biz.repository.live.LiveRoomUserRecordsRepository;
import com.treasure.mall.biz.service.core.live.LiveRoomUserRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 *
 * <p>
 * +---------------------------------------------------------
 * * @package: com.treasure.mall.biz.service.core.live.impl
 * * @author: guomw (guomwchen@foxmail.com)
 * * @date: 2020/9/17 1:36 下午
 * * @since: V1.0.0
 * +---------------------------------------------------------
 * 注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的
 * 
 */
@Service
public class LiveRoomUserRecordsServiceImpl implements LiveRoomUserRecordsService {
    @Autowired
    private LiveRoomUserRecordsRepository repository;

    /**
     * 进入直播间
     *
     * @param userId
     * @param sessionId
     */
    @Override
    public void enter(Long userId, String sessionId) {
        save(userId, sessionId, false);
    }

    /**
     * 离开直播间
     *
     * @param userId
     * @param sessionId
     */
    @Override
    public void leave(Long userId, String sessionId) {
        save(userId, sessionId, true);
    }


    private void save(Long userId, String sessionId, boolean isLeave) {
        LiveRoomUserRecordsPO po = new LiveRoomUserRecordsPO();
        po.setLeave(isLeave);
        po.setCreateTime(LocalDateTime.now());
        po.setSessionId(sessionId);
        po.setUserId(userId);
        repository.save(po);
    }

}
